package com.cn.jinhao.hotline.provider.huawu.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.hutool.json.JSONObject;
import com.cn.jinhao.hotline.provider.huawu.common.CtiCommon;
import com.cn.jinhao.hotline.provider.huawu.service.OpenApiService;
import com.cn.jinhao.hotline.provider.huawu.vo.SeatReqeustVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Random;

@RestController
@RequestMapping(value = "/api/openApi")
@Api(tags = {"坐席服务"})
@CrossOrigin
public class SeatController extends BaseController {
    OpenApiService openApiService;

    @Autowired
    public SeatController(OpenApiService openApiService) {
        this.openApiService = openApiService;
    }

    @ApiOperation(value = "新增", notes = "坐席列表新加入一个坐席")
    @PostMapping
    public RestResponse<Object> addSeat(@ApiParam(name = "坐席信息", value = "SeatReqeustVO", required = true) @Valid  @RequestBody SeatReqeustVO seatReqeustVO, BindingResult result) throws Exception {
        validate(result);
        String code = CtiCommon.generateCode();
        openApiService.add(code, seatReqeustVO.getPhone(),seatReqeustVO.getQueueCode());
        JSONObject jsonObject = new JSONObject("{\"code\":\"" + code + "\"}");
        return new RestResponse<>(jsonObject);
    }


}
